package com.lin.jdk.juc.queue;

import java.util.concurrent.SynchronousQueue;
import java.util.stream.IntStream;

public class SyncQueueTest {

    public static void main(String[] args) throws InterruptedException {

        SynchronousQueue<Integer> queue = new SynchronousQueue<>();
        IntStream.range(1, 2).forEach(i -> {
            new Thread(() -> {
                try {
                    System.out.println(Thread.currentThread().getName() + " tqueue.poll() = " + queue.take());
                } catch (InterruptedException e) {
                }
            }).start();
        });

        System.out.println("------------------------------------");

        IntStream.range(6, 9).forEach(i -> {
            new Thread(() -> {
                try {
                    queue.put(new Integer(i));
                } catch (InterruptedException e) {
                }
            }).start();
        });
        System.out.println("================================================");
    }


}
